﻿@{
    var grid = Html.DevExpress().GridView(settings =>
    {
        settings.Name = "listEmailConfig";
        settings.CallbackRouteValues = new { Controller = "Config", Action = "listEmailConfigPartial" };

        settings.SettingsEditing.AddNewRowRouteValues = new { Controller = "Config", Action = "listEmailConfigPartialAddNew" };
        settings.SettingsEditing.UpdateRowRouteValues = new { Controller = "Config", Action = "listEmailConfigPartialUpdate" };
        settings.SettingsEditing.DeleteRowRouteValues = new { Controller = "Config", Action = "listEmailConfigPartialDelete" };
        settings.CommandColumn.ButtonType = System.Web.UI.WebControls.ButtonType.Image;
        settings.CommandColumn.SetColVisibleIndex(0);
        settings.CommandColumn.Width = 100;
        settings.CommandColumn.SetHeaderCaptionTemplateContent("Tùy chọn");
        settings.CommandColumn.FixedStyle = GridViewColumnFixedStyle.Left;

        settings.CommandColumn.NewButton.Visible = true;
        settings.CommandColumn.NewButton.Image.Url = @Url.Content("~/Content/img/icon-24-new.png");
        settings.CommandColumn.NewButton.Image.ToolTip = "New";
        settings.CommandColumn.NewButton.Image.AlternateText = "Thêm";

        settings.CommandColumn.EditButton.Visible = true;
        settings.CommandColumn.EditButton.Image.Url = @Url.Content("~/Content/img/icon-24-edit.png");
        settings.CommandColumn.EditButton.Image.ToolTip = "Eidt";
        settings.CommandColumn.EditButton.Image.AlternateText = "Sửa";

        settings.CommandColumn.DeleteButton.Visible = true;
        settings.CommandColumn.DeleteButton.Image.Url = @Url.Content("~/Content/img/icon-24-delete.png");
        settings.CommandColumn.DeleteButton.Image.ToolTip = "Delete";
        settings.CommandColumn.DeleteButton.Image.AlternateText = "Xóa";

        settings.CommandColumn.UpdateButton.Visible = true;
        settings.CommandColumn.UpdateButton.Image.Url = @Url.Content("~/Content/img/icon-24-ok.png");
        settings.CommandColumn.UpdateButton.Image.ToolTip = "Update";
        settings.CommandColumn.UpdateButton.Image.AlternateText = "Lưu";

        settings.CommandColumn.CancelButton.Visible = true;
        settings.CommandColumn.CancelButton.Image.Url = @Url.Content("~/Content/img/icon-24-cancel.png");
        settings.CommandColumn.CancelButton.Image.ToolTip = "Cancel";
        settings.CommandColumn.CancelButton.Image.AlternateText = "Hủy";


        settings.SettingsEditing.Mode = GridViewEditingMode.PopupEditForm;
        settings.SettingsPopup.EditForm.AllowResize = true;
        settings.SettingsPopup.EditForm.HorizontalAlign = PopupHorizontalAlign.WindowCenter;
        settings.SettingsPopup.EditForm.VerticalAlign = PopupVerticalAlign.WindowCenter;
        settings.SettingsPopup.EditForm.Width = System.Web.UI.WebControls.Unit.Percentage(90);
        settings.SettingsPopup.EditForm.Height = System.Web.UI.WebControls.Unit.Percentage(90);
        settings.SettingsPopup.EditForm.Modal = true;
        settings.SettingsBehavior.ConfirmDelete = true;

        settings.CommandColumn.Visible = true;
        settings.CommandColumn.NewButton.Visible = true;
        settings.CommandColumn.DeleteButton.Visible = true;
        settings.CommandColumn.EditButton.Visible = true;

        settings.KeyFieldName = "ecid";

        settings.SettingsPager.Visible = true;
        settings.Settings.ShowGroupPanel = true;
        settings.Settings.ShowFilterRow = true;
        settings.SettingsBehavior.AllowSelectByRowClick = true;
        settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);
        settings.Settings.HorizontalScrollBarMode = ScrollBarMode.Auto;
        settings.Settings.VerticalScrollBarMode = ScrollBarMode.Hidden;

        settings.InitNewRow = (s, e) =>
        {
            e.NewValues["actionInTime"] = System.DateTime.Now;
        };
        ////edit init
        //settings.CellEditorInitialize = (sender, e) =>
        //{
        //    //ASPxGridView gridView = sender as ASPxGridView;
        //    //if (sender == null || !gridView.IsNewRowEditing)
        //    //return;
        //    if (e.Column.FieldName == "nguoiSuaCuoi")
        //    {
        //        e.Editor.Value = user_id;
        //    }
        //    if (e.Column.FieldName == "ngaySuaCuoi")
        //    {
        //        e.Editor.Value = System.DateTime.Now;
        //    }
        //};
        settings.Columns.Add(column =>
        {
            column.FieldName = "ecid";
            column.Caption = "Mã cấu hình";
            column.ColumnType = MVCxGridViewColumnType.TextBox;
            column.FixedStyle = GridViewColumnFixedStyle.Left;
            column.Visible = false;
            column.Width = 100;
        });
        settings.Columns.Add(column =>
        {
            column.FieldName = "host";
            column.Caption = "Tên host";
            column.ColumnType = MVCxGridViewColumnType.TextBox;
            column.Visible = true;
            column.Width = 100;
        });
        settings.Columns.Add(column =>
        {
            column.FieldName = "port";
            column.Caption = "Số port";
            column.ColumnType = MVCxGridViewColumnType.SpinEdit;
            var SpinEditPropertie = column.PropertiesEdit as SpinEditProperties;
            SpinEditPropertie.DisplayFormatString = "#";
            SpinEditPropertie.NumberType = SpinEditNumberType.Integer;
            SpinEditPropertie.Increment = 1;
            column.Visible = true;
            column.Width = 100;
        });

        settings.Columns.Add(column =>
        {
            column.FieldName = "userName";
            column.Caption = "Tài khoản";
            column.ColumnType = MVCxGridViewColumnType.TextBox;
            column.Visible = true;
            column.Width = 100;
        });

        settings.Columns.Add(column =>
        {
            column.FieldName = "passWord";
            column.Caption = "Mật khẩu";
            column.ColumnType = MVCxGridViewColumnType.TextBox;
            column.Visible = true;
            column.Width = 100;
        });
        settings.Columns.Add(column =>
        {
            column.FieldName = "actionDay";
            column.Caption = "Số ngày thực hiện";
            column.ColumnType = MVCxGridViewColumnType.SpinEdit;
            var SpinEditPropertie = column.PropertiesEdit as SpinEditProperties;
            SpinEditPropertie.DisplayFormatString = "#";
            SpinEditPropertie.NumberType = SpinEditNumberType.Integer;
            SpinEditPropertie.Increment = 1;
            column.Visible = true;
            column.Width = 100;
        });
        settings.Columns.Add(column =>
        {
            column.FieldName = "actionInTime";
            column.Caption = "Thời gian thực hiện";
            column.ColumnType = MVCxGridViewColumnType.TimeEdit;
            column.Visible = true;
            column.Width = 100;
        });
        settings.Columns.Add(column =>
        {
            column.FieldName = "reMindHour";
            column.Caption = "Số giờ nhắc lại";
            column.ColumnType = MVCxGridViewColumnType.SpinEdit;
            var SpinEditPropertie = column.PropertiesEdit as SpinEditProperties;
            SpinEditPropertie.DisplayFormatString = "#";
            SpinEditPropertie.NumberType = SpinEditNumberType.Integer;
            SpinEditPropertie.Increment = 1;
            column.Visible = true;
            column.Width = 100;
        });
        settings.Columns.Add(column =>
        {
            column.FieldName = "fAddress";
            column.Caption = "Địa chỉ gửi";
            column.ColumnType = MVCxGridViewColumnType.TextBox;
            column.Visible = true;
            column.Width = 100;
        });
        settings.Columns.Add(column =>
        {
            column.FieldName = "fDisplayName";
            column.Caption = "Tên người gửi";
            column.ColumnType = MVCxGridViewColumnType.TextBox;
            column.Visible = true;
            column.Width = 100;
        });
        settings.Columns.Add(column =>
        {
            column.FieldName = "tAddress";
            column.Caption = "Địa chị nhận 1";
            column.ColumnType = MVCxGridViewColumnType.TextBox;
            column.Visible = true;
            column.Width = 100;
        });
        settings.Columns.Add(column =>
        {
            column.FieldName = "tDisplayName";
            column.Caption = "Tên người nhận 1";
            column.ColumnType = MVCxGridViewColumnType.TextBox;
            column.Visible = true;
            column.Width = 100;
        });
        settings.Columns.Add(column =>
        {
            column.FieldName = "tsAddress";
            column.Caption = "Địa chị nhận 2";
            column.ColumnType = MVCxGridViewColumnType.TextBox;
            column.Visible = true;
            column.Width = 100;
        });
        settings.Columns.Add(column =>
        {
            column.FieldName = "tsDisplayName";
            column.Caption = "Tên người nhận 2";
            column.ColumnType = MVCxGridViewColumnType.TextBox;
            column.Visible = true;
            column.Width = 100;
        });
        
        settings.Columns.Add(column =>
        {
            column.FieldName = "isActive";
            column.Caption = "Áp dụng";
            column.ColumnType = MVCxGridViewColumnType.CheckBox;
            column.Width = 60;
            column.FixedStyle = GridViewColumnFixedStyle.Left;
            column.SetDataItemTemplateContent(c =>
            {
                bool actived = (bool)DataBinder.Eval(c.DataItem, "isActive");
                object makh_obj = DataBinder.Eval(c.DataItem, "ecid");
                string updateLink = Url.Action("ToogleActive", "Base", new { keyvalue = makh_obj, active = !actived, tablename = "tblEmailConfig", keyname = "ecid" });
                ViewContext.Writer.Write(
                    "<a href=\"" + updateLink + "\" id=\"id_button_active_" + makh_obj + "\" class=\"button btn-active\"><i class=\"font-icon-" + (actived ? "check" : "check-empty") + "\"></i></a>"
                );
            });
        });

    });
    if (ViewData["EditError"] != null)
    {
        grid.SetEditErrorText((string)ViewData["EditError"]);
    }
}
@grid.Bind(Model).GetHtml()